<template>
	<view class="pagesBox">
		<view class="pagesMain">
			<view class="jifenBox">
				<view class="jifenItem">
					<view class="jifenTitle">待发放</view>
					<view class="jifenNum">{{scoreInfo.score_wait || "0.00"}}</view>
				</view>
				<view class="jifenItem">
					<view class="jifenTitle">已完结</view>
					<view class="jifenNum">{{scoreInfo.score_settle || "0.00"}}</view>
				</view>
			</view>
			<view class="recordBox">
				<block v-for="(item,index) in flowRecord" :key="index">
					<view class="recordItem">
						<view class="recordLeft">
							<view class="imageBox">
								<image v-if="!item.money.includes('-')" :src="`${baseUrl}/static/my/icon20.png`" style="width: 80rpx;height: 80rpx;"></image>
								<image v-if="item.money.includes('-')" :src="`${baseUrl}/static/my/icon21.png`" style="width: 80rpx;height: 80rpx;"></image>
							</view>
							<view class="recordInfo">
								<view class="recordTitle">{{item.memo}}</view>
								<view class="recordTime">{{item.time}}</view>
							</view>
						</view>
						<view class="recordRight" :class="[item.money.includes('-') ? 'money1':'money2']">{{item.money}}</view>
					</view>
				</block>
				<uni-load-more v-if="total > 0" :status="statusType"></uni-load-more>
				<view style="margin-top: 20rpx;" v-if="total == 0"><u-empty text="暂无明细" mode="list"></u-empty></view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseUrl:this.$baseUrl,
				scoreInfo:{},
				flowRecord:[],
				total:-1,
				statusType:'more',
				params:{
					limit:15,
					page:1
				},
			};
		},
		onLoad(options) {
			this.getScoreInfo()
			this.getRecord();
		},
		methods:{
			async getScoreInfo(){
				let res = await uni.$http('POST','score/index');
				console.log("积分信息",res);
				if(res.code == 1){
					this.scoreInfo = res.data;
				}else if(res.msg.includes('登录')){
					uni.setStorageSync('token',0);
				}
			},
			async getRecord(){
				let res = await uni.$http('POST','score/record',this.params);
				if(res.code == 1){
					this.params.page = res.data.current_page;
					this.total = res.data.total;
					if(this.params.page == 1){
						this.flowRecord = res.data.data;
					}else{
						this.flowRecord = this.flowRecord.concat(res.data.data);
					}
					if(this.flowRecord.length < this.total){
						this.statusType = 'more'
					}else{
						this.statusType = 'noMore'
					}
				}else if(res.msg.includes('登录')){
					this.total = 0;
					uni.removeStorageSync("token")
				}else{
					this.total = 0;
				}
			}
		},
		onReachBottom() {
			if(this.flowRecord.length < this.total){
				this.statusType = 'loading';
				this.params.page++;
				this.getRecord()
			}else{
				this.statusType = 'noMore'
			}
		}
	}
</script>

<style scoped lang="scss">
.pagesBox{
	.pagesMain{
		padding: 12rpx 24rpx;
		.jifenBox{
			height: 200rpx;
			color: #fff;
			background-color: #2BA777;
			border-radius: 16rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			.jifenItem{
				width: 49%;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				.jifenTitle{
					font-size: 32rpx;
				}
				.jifenNum{
					font-size: 32rpx;
					font-weight: 600;
					margin-top: 16rpx;
				}
			}
		}
		.recordBox{
			background-color: #FFFFFF;
			border-radius: 16rpx;
			padding: 0 24rpx;
			margin-top: 16rpx;
			.recordItem{
				border-bottom: 2rpx solid #f7f8fa;
				display: flex;
				justify-content: space-between;
				align-items: center;
				&:last-of-type{
					border-bottom: 0rpx;
				}
				.recordLeft{
					font-weight: 400;
					font-size: 32rpx;
					color: #16202B;
					padding: 24rpx 0;
					margin-bottom: 8rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					.imageBox{
						font-size: 0%;
						margin-right: 12rpx;
					}
					.recordInfo{
						.recordTitle{
						    font-weight: 600;
						    font-size: 30rpx;
						    color: #000;
						}
						.recordTime{
						    font-weight: 400;
						    font-size: 24rpx;
						    color: #A1A5AA;
							margin-top: 6rpx;
						}
					}
				}
				.money1{
					font-weight: 600;
					font-size: 30rpx;
					color: #FF6938;
				}
				.money2{
					font-weight: 600;
					font-size: 30rpx;
					color: #53C588;
				}
			}
		}
	}
}
</style>
<style>
	page{
		background-color: #F7F8FA;
	}
</style>
